package String;

public class string_builder {
    public static void main(String[] args) {
      StringBuilder sb= new StringBuilder("abc");

      //添加元素
        sb.append(1);
        System.out.println(sb);
        sb.append(2.3);
        System.out.println(sb);
        sb.append("abc");
        System.out.println(sb);

        //反转元素
        sb.reverse();
        System.out.println(sb);
        sb.append(true);
        System.out.println(sb);

        //获取长度
        int len=sb.length();
        System.out.println(len);


        //把StringBuilder变回字符串
        String str=sb.toString();
        System.out.println(str);


        //StringBuilder的容量
      StringBuilder sb6=new StringBuilder();
      //容量：最多装多少
      //长度：已经装了多少
      System.out.println(sb6.capacity());//16,原容量
      System.out.println(sb6.length());//0


      sb6.append("abchkjlhhhfdgbnjkhklfhkjluigyihuoiihpiiiuhiyuguyiyglhkj");

      System.out.println(sb6.capacity());//55
      System.out.println(sb6.length());//55
    }
}
